package com.thread;

/**
 * @author :admin
 * @description: 线程变量共享,特殊实例，同步方法之前的任何共享操作都可能导致非线程安
 * @create date: 2019/4/3 10:53
 */
public class ThreadShare_problem implements Runnable{

    private int count=5;

    @Override
    public void run() {
        String name = Thread.currentThread().getName();
//        --count发生在print之前，存在线程安全
        System.out.println("current thread run name :" + name +" count :"+(--count));
    }

    public static void main(String[] args){
        ThreadShare_problem threadShare=new ThreadShare_problem();
        Thread thread=new Thread(threadShare,"A1");
        Thread thread1=new Thread(threadShare,"A2");
        Thread thread2=new Thread(threadShare,"A3");
        thread.start();
        thread1.start();
        thread2.start();
    }
}
